<template>
  <div>
    <el-row>
      <!-- 用户列表功能按钮 开始 -->
      <el-col :span="24">
        <el-button style="margin: 5px 5px" type="primary" @click="editSelection"
          ><el-icon><EditPen /></el-icon>编辑选中的用户</el-button
        >
        <el-button style="margin: 5px 5px" type="danger"
          ><el-icon><Delete /></el-icon>删除选中的客户</el-button
        >
        <el-button
          @click="dialogSaveCustomerVisible = true"
          style="margin: 5px 5px"
          type="success"
          ><el-icon><Plus /></el-icon>添加新客户</el-button
        >
      </el-col>
      <!-- 功能按钮 结束 -->
    </el-row>

    <!-- 添加客戶弹窗组件 开始 -->
    <el-dialog width="80%" v-model="dialogSaveCustomerVisible" title="添加客戶">
      <el-form :model="newCustomer">
        <el-row>
          <el-col :span="6">
            <el-form-item label="客户编号" :label-width="formLabelWidth">
              <el-input v-model="newCustomer.customerNo" autocomplete="off" />
            </el-form-item>
          </el-col>
          <el-col :span="2"><el-button @click="genNewNo" type="success">生成</el-button></el-col>
          <el-col :span="8">
            <el-form-item label="客户名称" :label-width="formLabelWidth">
              <el-input v-model="newCustomer.customerName" autocomplete="off" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="客户简称" :label-width="formLabelWidth">
              <el-input
                v-model="newCustomer.customerNickname"
                autocomplete="off"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="英文名称" :label-width="formLabelWidth">
              <el-input
                v-model="newCustomer.customerEnName"
                autocomplete="off"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="客户电话" :label-width="formLabelWidth">
              <el-input v-model="newCustomer.customerTel" autocomplete="off" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="客户邮箱" :label-width="formLabelWidth">
              <el-input
                v-model="newCustomer.customerEmail"
                autocomplete="off"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="客户官网" :label-width="formLabelWidth">
              <el-input
                v-model="newCustomer.customerWebsit"
                autocomplete="off"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="信用代码" :label-width="formLabelWidth">
              <el-input v-model="newCustomer.customerCode" autocomplete="off" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="客户地址" :label-width="formLabelWidth">
              <el-input v-model="newCustomer.customerAddr" autocomplete="off" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="客户简介" :label-width="formLabelWidth">
              <el-input
                :rows="2"
                type="textarea"
                v-model="newCustomer.customerDesc"
                autocomplete="off"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="客户类别" :label-width="formLabelWidth">
              <el-select
                v-model="newCustomer.customerCat"
                class="m-2"
                placeholder="客户类别"
                size="large"
              >
                <el-option
                  v-for="item in cats"
                  :key="item.dataId"
                  :label="item.dataTag"
                  :value="item.dataValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="客户区域" :label-width="formLabelWidth">
              <el-select
                v-model="newCustomer.customerArea"
                class="m-2"
                placeholder="客户区域"
                size="large"
              >
                <el-option
                  v-for="item in areas"
                  :key="item.dataId"
                  :label="item.dataTag"
                  :value="item.dataValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="客户级别" :label-width="formLabelWidth">
              <el-select
                v-model="newCustomer.customerLevel"
                class="m-2"
                placeholder="客户级别"
                size="large"
              >
                <el-option
                  v-for="item in levels"
                  :key="item.dataId"
                  :label="item.dataTag"
                  :value="item.dataValue"
                />
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="联系人1" :label-width="formLabelWidth">
              <el-input v-model="newCustomer.linkman1Name" autocomplete="off" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系人1电话" :label-width="formLabelWidth">
              <el-input v-model="newCustomer.linkman1Tel" autocomplete="off" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系人1邮箱" :label-width="formLabelWidth">
              <el-input
                v-model="newCustomer.linkman1Email"
                autocomplete="off"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="联系人2" :label-width="formLabelWidth">
              <el-input v-model="newCustomer.linkman2Name" autocomplete="off" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系人2电话" :label-width="formLabelWidth">
              <el-input v-model="newCustomer.linkman2Tel" autocomplete="off" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系人2邮箱" :label-width="formLabelWidth">
              <el-input
                v-model="newCustomer.linkman2Email"
                autocomplete="off"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <!-- 将显示窗体的属性修改为false的同时，将newUser置空 -->
          <el-button
            @click="
              dialogSaveCustomerVisible = false;
              this.newCustomer = {};
            "
            >取消</el-button
          >
          <el-button type="primary" @click="doSaveUser"> 提交 </el-button>
        </span>
      </template>
    </el-dialog>
    <!-- 添加客戶弹窗组件 结束 -->
  </div>
</template>

<script>
import customerHttp from "../../../api/customer.js";
import dictHttp from "../../../api/dict.js";
export default {
  data() {
    return {
      newCustomer: {}, // 新添加的客戶對象
      dialogSaveCustomerVisible: false, // 添加客戶的窗体显示标记
      cats: [], // 客户类别集合
      levels: [], // 客户级别集合
      areas: [], // 客户区域集合
    };
  },methods:{

    /**
     * 产生新的编号
     */
    genNewNo(){
        customerHttp.getNewNo(res=>{
            // 将res中的data的值设置给newCustomer
            this.newCustomer.customerNo=res.data;
        });
    },
  },mounted(){
    dictHttp.getCustomerArea(res=>{
        this.areas = res.data.dictDataList;
    });
    dictHttp.getCustomerCat(res=>{
        this.cats = res.data.dictDataList;
    })
    dictHttp.getCustomerLevel(res=>{
        this.levels = res.data.dictDataList;
    });
  }
};
</script>

<style>
</style>